var Line = AbstractPrimitive.extend({
    init: function(start, end){
        this._start = start;
        this._end = end;
    },
    setStart: function(start){
        this._start = start;
    },
    setEnd: function(end){
        this._end = end;
    },
    getStart: function(){
        return this._start;
    },
    getEnd: function(){
        return this._end;
    },
    getLength: function () {
        var x1 = this.getStart().getX(), y1 = this.getStart().getY(), x2 = this.getEnd().getX() ,y2 = this.getEnd().getY();
        return Math.sqrt((x1 -= x2)*x1 + (y1 -= y2)*y1);
    },
    getIntersection: function(line){
        var pt1Dir = new Point(this.getEnd().getX() - this.getStart().getX(), this.getEnd().getY() - this.getStart().getY());
        var pt2Dir = new Point(line.getEnd().getX() - line.getStart().getX(), line.getEnd().getY() - line.getStart().getY());
        var det = (pt1Dir.getX() * pt2Dir.getY()) - (pt1Dir.getY() * pt2Dir.getX());
        var deltaPt = new Point(line.getStart().getX() - this.getStart().getX(), line.getStart().getY() - this.getStart().getY());
        var alpha = (deltaPt.getX() * pt2Dir.getY()) - (deltaPt.getY() * pt2Dir.getX());
        var beta = (deltaPt.getX() * pt1Dir.getY()) - (deltaPt.getY() * pt1Dir.getX());

        if (det === 0 || alpha * det < 0 || beta * det < 0){
            return null;
        }

        if (det > 0){
            if (alpha > det || beta > det){
                return null;
            }
        } else {
            if (alpha < det || beta < det){
                return null;
            }
        }
        return new Point(this.getStart().getX() + (alpha * pt1Dir.getX() / det), this.getStart().getY() + (alpha * pt1Dir.getY() / det));
    },
    getXAxisRadius: function(){
        var y = -(this.getEnd().getY() - this.getStart().getY()),	// invert the y-axis
            x = this.getEnd().getX() - this.getStart().getX(),
            rad = Math.atan2(y, x);
        if (rad < 0){ // correction for III. and IV. quadrant
            rad = 2*Math.PI + rad;
        }
        var degree =  180*rad / Math.PI;
        return degree;
    }
});